package com.hltc.mtmap.orm;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;

import com.hltc.mtmap.orm.MTUserDao;
import com.hltc.mtmap.orm.MGrainDao;
import com.hltc.mtmap.orm.MTMyGrainDao;
import com.hltc.mtmap.orm.MTMessageDao;
import com.hltc.mtmap.orm.MTMyFavouriteDao;
import com.hltc.mtmap.orm.MFriendStatusDao;
import com.hltc.mtmap.orm.MFriendDao;
import com.hltc.mtmap.orm.MTGrainDao;
import com.hltc.mtmap.orm.MTSiteDao;
import com.hltc.mtmap.orm.MTPhotoDao;
import com.hltc.mtmap.orm.MTCategoryDao;
import com.hltc.mtmap.orm.MTCommentDao;
import com.hltc.mtmap.orm.MTFavouriteDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * Master of DAO (schema version 1): knows all DAOs.
 */
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    public DaoMaster(SQLiteDatabase db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(MTUserDao.class);
        registerDaoClass(MGrainDao.class);
        registerDaoClass(MTMyGrainDao.class);
        registerDaoClass(MTMessageDao.class);
        registerDaoClass(MTMyFavouriteDao.class);
        registerDaoClass(MFriendStatusDao.class);
        registerDaoClass(MFriendDao.class);
        registerDaoClass(MTGrainDao.class);
        registerDaoClass(MTSiteDao.class);
        registerDaoClass(MTPhotoDao.class);
        registerDaoClass(MTCategoryDao.class);
        registerDaoClass(MTCommentDao.class);
        registerDaoClass(MTFavouriteDao.class);
    }

    /**
     * Creates underlying database table using DAOs.
     */
    public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
        MTUserDao.createTable(db, ifNotExists);
        MGrainDao.createTable(db, ifNotExists);
        MTMyGrainDao.createTable(db, ifNotExists);
        MTMessageDao.createTable(db, ifNotExists);
        MTMyFavouriteDao.createTable(db, ifNotExists);
        MFriendStatusDao.createTable(db, ifNotExists);
        MFriendDao.createTable(db, ifNotExists);
        MTGrainDao.createTable(db, ifNotExists);
        MTSiteDao.createTable(db, ifNotExists);
        MTPhotoDao.createTable(db, ifNotExists);
        MTCategoryDao.createTable(db, ifNotExists);
        MTCommentDao.createTable(db, ifNotExists);
        MTFavouriteDao.createTable(db, ifNotExists);
    }
    
    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
        MTUserDao.dropTable(db, ifExists);
        MGrainDao.dropTable(db, ifExists);
        MTMyGrainDao.dropTable(db, ifExists);
        MTMessageDao.dropTable(db, ifExists);
        MTMyFavouriteDao.dropTable(db, ifExists);
        MFriendStatusDao.dropTable(db, ifExists);
        MFriendDao.dropTable(db, ifExists);
        MTGrainDao.dropTable(db, ifExists);
        MTSiteDao.dropTable(db, ifExists);
        MTPhotoDao.dropTable(db, ifExists);
        MTCategoryDao.dropTable(db, ifExists);
        MTCommentDao.dropTable(db, ifExists);
        MTFavouriteDao.dropTable(db, ifExists);
    }
    
    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }

    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }
    
    public static abstract class OpenHelper extends SQLiteOpenHelper {

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }
    
    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }
    
}
